import { createApp } from 'vue'
import App from './App.vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import './assets/main.css'
import { createPinia } from 'pinia'
// 2、引入router 并注册（app.use(router)）
import router from './router/index'


router.beforeEach((to,from,next)=>{
    const role = localStorage.getItem("token");
    if (!role && to.path !== '/login') {
        next('/login');
    } else {
     if(role && to.path === '/login'){
        next('/');
      }
     next();
    }
})



const app = createApp(App)
app.use(ElementPlus)
app.use(router)
app.use(createPinia())

app.mount('#app')
